
$().ready(function() {
    // validateRule();

    layui.use(['transfer', 'layer', 'util'], function(){
        var $ = layui.$
            ,transfer = layui.transfer
            ,layer = layui.layer
            ,util = layui.util;

        var userId = $('#userId').val()
        $.ajax({
            type : 'POST',
            data : { "userId" : userId },
            url : ctx + 'sys/user/realationList',
            success : function(r) {
                if (r.code == 0) {
                    //基础效果
                    transfer.render({
                        elem: '#test1'
                        ,data: r.shops
                        ,width:500
                        ,height:500
                        ,value: r.relation_list
                        ,title: ['未绑定企业','已绑定企业']  //自定义标题
                        ,showSearch: true
                        ,onchange: function(obj, index){
                            console.log('obj',obj)
                            console.log('index',index)
                            var arr = ['左边', '右边'];
                            layer.alert('来自 <strong>'+ arr[index] + '</strong> 的数据：'+ JSON.stringify(obj)); //获得被穿梭时的数据

                            bandShop(userId,index,JSON.stringify(obj));
                        }
                    })
                } else {
                    layer.msg(r.msg);
                }
            }
        });
    });
});


function bandShop(user_id, op_type,data) {
    $.ajax({
        type : 'POST',
        data : {
            "userId" : user_id,
            "op_type" : op_type,
            "shops" : data,
        },
        url : ctx + 'sys/user/bandShop',
        success : function(r) {
            // if (r.code == 0) {
            //     //基础效果
            // } else {
            //     layer.msg(r.msg);
            // }
            layer.msg(r.msg);
        }
    });
}